package com.my.mycommoncore.utils;

import cn.hutool.crypto.digest.DigestUtil;
import org.apache.commons.lang3.StringUtils;

import cn.hutool.crypto.SecureUtil;
import java.nio.charset.StandardCharsets;
public class AESUtil {

    /**
     * keys
     */
    private static final byte[] KEYS = "12345678abcdefgh".getBytes(StandardCharsets.UTF_8);

    /**
     * aes加密
     * @param data 原始数据
     * @return 加密后的数据
     */
    public static String encrypt(String data) {
        if(StringUtils.isNotEmpty(data)){
            return SecureUtil.aes(KEYS).encryptHex(data);
        }
        return null;
    }
    public static String decrypt(String data) {
        if(StringUtils.isNotEmpty(data)){
            return SecureUtil.aes(KEYS).decryptStr(data);
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(encrypt("123456789"));
//        System.out.println(decrypt("f10bd64cefdb5cf15e2f2adb5f8dfbc3"));
        String s="f10bd64cefdb5cf15e2f2adb5f8dfbc3";
        System.out.println(DigestUtil.sha256Hex(s));
    }
}
